namespace WSCeCommerce.Domain.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        CategoryId = c.Int(nullable: false, identity: true),
                        CategoryName = c.String(),
                    })
                .PrimaryKey(t => t.CategoryId);
            
            CreateTable(
                "dbo.Items",
                c => new
                    {
                        ItemId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Price = c.Single(nullable: false),
                    })
                .PrimaryKey(t => t.ItemId);
            
            CreateTable(
                "dbo.Addresses",
                c => new
                    {
                        AddressId = c.Int(nullable: false, identity: true),
                        City = c.String(),
                        Country = c.String(),
                        Zip = c.String(),
                        AddressLine1 = c.String(),
                        AddressLine2 = c.String(),
                        AddressType = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.AddressId);
            
            CreateTable(
                "dbo.UserAddresses",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        Address_AddressId = c.Int(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.Addresses", t => t.Address_AddressId)
                .Index(t => t.Address_AddressId);
            
            CreateTable(
                "dbo.Sales",
                c => new
                    {
                        SaleId = c.Int(nullable: false, identity: true),
                        Date = c.DateTime(nullable: false),
                        UserId = c.Int(nullable: false),
                        Total = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ShipToAddress_AddressId = c.Int(),
                    })
                .PrimaryKey(t => t.SaleId)
                .ForeignKey("dbo.Addresses", t => t.ShipToAddress_AddressId)
                .Index(t => t.ShipToAddress_AddressId);
            
            CreateTable(
                "dbo.SaleItems",
                c => new
                    {
                        SaleItemId = c.Int(nullable: false, identity: true),
                        Item_ItemId = c.Int(nullable: false),
                        Quantity = c.Int(nullable: false),
                        Price = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Sale_SaleId = c.Int(),
                        Item_ItemId1 = c.Int(),
                    })
                .PrimaryKey(t => t.SaleItemId)
                .ForeignKey("dbo.Sales", t => t.Sale_SaleId)
                .ForeignKey("dbo.Items", t => t.Item_ItemId1)
                .Index(t => t.Sale_SaleId)
                .Index(t => t.Item_ItemId1);
            
            CreateTable(
                "dbo.ItemCategories",
                c => new
                    {
                        Item_ItemId = c.Int(nullable: false),
                        Category_CategoryId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Item_ItemId, t.Category_CategoryId })
                .ForeignKey("dbo.Items", t => t.Item_ItemId, cascadeDelete: true)
                .ForeignKey("dbo.Categories", t => t.Category_CategoryId, cascadeDelete: true)
                .Index(t => t.Item_ItemId)
                .Index(t => t.Category_CategoryId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.ItemCategories", new[] { "Category_CategoryId" });
            DropIndex("dbo.ItemCategories", new[] { "Item_ItemId" });
            DropIndex("dbo.SaleItems", new[] { "Item_ItemId1" });
            DropIndex("dbo.SaleItems", new[] { "Sale_SaleId" });
            DropIndex("dbo.Sales", new[] { "ShipToAddress_AddressId" });
            DropIndex("dbo.UserAddresses", new[] { "Address_AddressId" });
            DropForeignKey("dbo.ItemCategories", "Category_CategoryId", "dbo.Categories");
            DropForeignKey("dbo.ItemCategories", "Item_ItemId", "dbo.Items");
            DropForeignKey("dbo.SaleItems", "Item_ItemId1", "dbo.Items");
            DropForeignKey("dbo.SaleItems", "Sale_SaleId", "dbo.Sales");
            DropForeignKey("dbo.Sales", "ShipToAddress_AddressId", "dbo.Addresses");
            DropForeignKey("dbo.UserAddresses", "Address_AddressId", "dbo.Addresses");
            DropTable("dbo.ItemCategories");
            DropTable("dbo.SaleItems");
            DropTable("dbo.Sales");
            DropTable("dbo.UserAddresses");
            DropTable("dbo.Addresses");
            DropTable("dbo.Items");
            DropTable("dbo.Categories");
        }
    }
}
